<?php

require_once(DIR_LIB."VsGui".DIR_SEP."vssmartywidget.php");

require_once(DIR_LIB."Junona".DIR_SEP."junobjectsfactory.php");

require_once(dirname(__FILE__).DIR_SEP."vsdateedit.php");

class XCartOperatorsWorkSummary extends VsSmartyWidget {

	function __construct(&$page, $groupId, $forPrint=FALSE, $pager=NULL) {
		// Ne go zabravqj ina4e nqma $smarty Object
		parent::__construct();

		if($forPrint)
			$this->_template = dirname(__FILE__).DIR_SEP."xcart_operators_work_summary_print.html";
		else
			$this->_template = dirname(__FILE__).DIR_SEP."xcart_operators_work_summary.html";
			

		$this->_wwwDir = 'templates/XCart/';
		$this->assign('wwwDir', $this->_wwwDir);

		$page->addJsFile($this->_wwwDir."js/vsprint.js");


		//$minDate = isset($_POST['fromVsdeDate']) ? $_POST['fromVsdeDate'] : date("Y-m-d", mktime(0, 0, 0, date("m")-1, date("d"),   date("Y")));
		//$minDate = isset($_POST['fromVsdeDate']) ? $_POST['fromVsdeDate'] : date("Y-m-d", strtotime("-2 week"));
		$minDate = isset($_POST['fromVsdeDate']) ? $_POST['fromVsdeDate'] : date("Y-m-d");
		$maxDate = isset($_POST['toVsdeDate']) ? $_POST['toVsdeDate'] : date("Y-m-d");
		//echo "FROM: ".$minDate."  TO:  ".$maxDate;
		//echo "FROM: ".$_POST['fromVsdeDate']."  TO:  ".$_POST['toVsdeDate'];

		$fromDateEdit = new VsDateEdit($page, $minDate);
		$this->assign('fromDateEdit',  $fromDateEdit->show());
		$this->assign('fromVsdeDate',  $fromDateEdit->date());

		$toDateEdit = new VsDateEdit($page, $maxDate);
		$this->assign('toDateEdit',  $toDateEdit->show());
		$this->assign('toVsdeDate',  $toDateEdit->date());


		//$filterGroup = isset($_REQUEST['group']) ? $_REQUEST['group'] : -1;
		$filterGroup = $groupId;
		$opWork = JunObjectsFactory::operatorsWork($groupId, $fromDateEdit->date(), $toDateEdit->date());

		$this->assign('filterGroup', $filterGroup);
		$this->assign('listGroups', JunObjectsFactory::makeOperatorGroups());

		$this->assign('opWork', $opWork[0]);
		$this->assign('opWorkTotal', $opWork[1]);

		if($pager)
			$this->assign('pager', $pager->show());
		else
			$this->assign('pager', '');
	}
	//============================================================================

	function show() {
		return $this->fetch($this->_template);
	}
	//============================================================================


};

?>
